<template>
  <div>
    <tabs />
    <div class="survey-box">
      <el-row type="flex" justify="space-between" align="middle" class="survey-hedaer">
        <div class="title">课程详情分析{{ (' - ' + response.title) || '' }}</div>
        <box-header-right :school="false" @update:date="updateDate" />
      </el-row>
      <el-row type="flex" justify="space-between" class="user">
        <div class="item">
          <div class="title">
            <count-roll :number="response.pv" />
          </div>
          <div class="name">访问量(PV)</div>
        </div>

        <div class="item">
          <div class="title">
            <count-roll :number="response.uv" />
          </div>
          <div class="name">独立访客数(UV)</div>
        </div>

        <div class="item">
          <div class="title">
            <count-roll :number="response.place_count" />
          </div>
          <div class="name">下单数</div>
        </div>

        <div class="item">
          <div class="title">
            <count-roll :number="response.place_payment_count" />
          </div>
          <div class="name">支付数</div>
        </div>

        <div class="item">
          <div class="title">
            <count-roll :number="response.payment_total" :is-money="true" />
          </div>
          <div class="name">结算金额</div>
        </div>

        <div class="item">
          <div class="title">{{ response.place_conversion | preSymbol }}</div>
          <div class="name">下单转化率</div>
        </div>

        <div class="item">
          <div class="title">{{ response.payment_conversion | preSymbol }}</div>
          <div class="name">支付转化率</div>
        </div>
      </el-row>
      <el-row class="ve-line-box">
        <ve-line :loading="loading" :data="chartData" :settings="chartSettings" :colors="colors" :extend="extendsConfig" />
      </el-row>
    </div>
  </div>
</template>

<script>
import Tabs from '../../tabs/index.vue';
import VeLine from 'v-charts/lib/line.common';
import 'v-charts/lib/style.css';
import BoxHeaderRight from '@/pages/data/components/daterange.vue';
import CountRoll from '@/pages/data/components/count_roll';
import echarts from 'echarts';

export default {
  components: {
    VeLine,
    BoxHeaderRight,
    CountRoll,
    Tabs
  },
  data() {
    return {
      daterange: null,
      loading: false,
      response: {},
      chartSettings: {
        labelMap: {
          date: '日期',
          pv: '访问量(PV)',
          uv: '独立访客数(UV)'
        },
        xAxisType: 'category',
        yAxisType: ['KMB'],
        area: true,
        scale: [true, false]
      },
      chartData: {
        columns: ['date', 'pv', 'uv'],
        rows: []
      },
      colors: [
        // 颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
        new echarts.graphic.LinearGradient(0, 1, 0, 0, [
          {
            offset: 0,
            color: '#C8E3FF'
          },
          {
            offset: 0.6,
            color: '#C8E7FF'
          }
        ]),
        new echarts.graphic.LinearGradient(0, 1, 0, 0, [
          {
            offset: 0,
            color: '#FFEAD6'
          },
          {
            offset: 0.6,
            color: '#FFDBA8'
          }
        ])
      ],
      extendsConfig: {
        grid: {
          right: 20
        },
        xAxis(v) {
          v.forEach(i => {
            i.boundaryGap = false;
            i.axisLabel = {
              showMaxLabel: true,
              rotate: 45
            };
          });

          return v;
        },
        yAxis(v) {
          v.forEach(i => {
            i.minInterval = 1;
          });

          return v;
        }
      }
    };
  },
  created() {
    this.loadData();
  },
  mounted() {
    this.$store.dispatch('setLoading', 0);
  },
  methods: {
    updateDate: function (date) {
      this.daterange = date;
      this.loading = true;
      this.loadData();
    },
    loadData: function () {
      this.$http.get(
        '/admin/data/course/' + this.$route.params.id + '/details',
        {
          daterange: this.daterange
        },
        response => {
          this.response = response.data;
          this.chartData.rows = this.response.rows;
          this.loading = false;
        },
        errror => {
          this.loading = false;
        },
        false
      );
    }
  }
};
</script>

<style lang="scss" scoped>
.survey-box {
  background-color: #fff;
  min-height: 150px;
  margin-bottom: 20px;
  padding: 10px 20px 25px;
  .survey-hedaer {
    margin-bottom: 28px;
    height: 36px;
    padding-right: 20px;
    background-color: #f1f8ff;
    .title {
      color: #303133;
      font-size: 15px;
      padding-left: 6px;
      border-left: 2px solid #5191ff;
    }
  }
  .user {
    .item {
      padding: 18px;
      text-align: center;
      border-radius: 4px;
      width: calc(100% / 7 - 10px);
      box-sizing: border-box;
      &:nth-child(1) {
        background: linear-gradient(
          226deg,
          rgba(255, 212, 65, 1) 0%,
          rgba(250, 165, 0, 1) 100%
        );
      }
      &:nth-child(2) {
        background: linear-gradient(
          226deg,
          rgba(115, 164, 255, 1) 0%,
          rgba(60, 143, 255, 1) 100%
        );
      }
      &:nth-child(3) {
        background: linear-gradient(
          226deg,
          rgba(255, 172, 118, 1) 0%,
          rgba(255, 142, 70, 1) 100%
        );
      }
      &:nth-child(4) {
        background: linear-gradient(
          225deg,
          rgba(173, 232, 89, 1) 0%,
          rgba(131, 219, 49, 1) 100%
        );
      }
      &:nth-child(5) {
        background: linear-gradient(
          226deg,
          rgba(255, 149, 132, 1) 0%,
          rgba(255, 113, 105, 1) 100%
        );
      }
      &:nth-child(6) {
        background: linear-gradient(
          45deg,
          rgba(123, 114, 255, 1) 0%,
          rgba(135, 161, 255, 1) 100%
        );
      }
      &:nth-child(7) {
        background: linear-gradient(
          226deg,
          rgba(255, 124, 3, 1) 0%,
          rgba(255, 124, 100, 1) 100%
        );
      }
      .title {
        color: #fff;
        font-weight: bold;
        font-size: 22px;
      }
      .name {
        color: #fff;
        font-size: 14px;
        margin-top: 13px;
      }
    }
  }
  .ve-line-box {
    margin-top: 24px;
    border: 1px solid #e4e7ed;
    padding: 20px 20px 0 20px;
  }
}
</style>
